home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MYMUD21.ZIP / MMUD21.ZIP / SOURCE / SOURCE.ZIP / LOWLEVEL.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-01-21  |  26.7 KB  |  980 lines

  1. {$I COPYRGHT.INC}
  2.  
  3. (*---------------------------------------------------------------------------*
  4.    General LowLevel routines
  5.  *---------------------------------------------------------------------------*)
  6.  
  7. Unit LowLevel;
  8. Interface
  9. Uses Dos,
  10.      MyIO,    { ReadKey -> Get password function! }
  11.      Misc,
  12.      Header,
  13.      Multi,
  14.      BIN_DB;
  15.  
  16. (*---------------------------------------------------------------------------*
  17.   Move an object to the contents chain of an other object.
  18.  *---------------------------------------------------------------------------*)
  19. Procedure MoveTo(ObjNr,ToObj : Integer);
  20.  
  21. (*---------------------------------------------------------------------------*
  22.   Handle DRONE's. Exitnr is not used at this moment. Current.room should
  23.   containt the TO room. FromRoom should contain the current location.
  24.  *---------------------------------------------------------------------------*)
  25.  
  26. Procedure HandleDrones( ExitNr   : Integer;
  27.                         Current  : ContextType;
  28.                         FromRoom : Integer);
  29.  
  30. (*---------------------------------------------------------------------------*
  31.   Unlink an object.
  32.  *---------------------------------------------------------------------------*)
  33. Procedure Unlink(ObjNr : Integer);
  34.  
  35.  
  36. (*---------------------------------------------------------------------------*
  37.   Check if a string is part of a ; delimited list
  38.  *---------------------------------------------------------------------------*)
  39. Function CheckName(S,List : String):Boolean;
  40.  
  41. (*---------------------------------------------------------------------------*
  42.   Check if a word is exact matched within a string.
  43.  *---------------------------------------------------------------------------*)
  44. Function ExactWordMatch(FWord,Line : String):Boolean;
  45. Function FussyWordMatch(FWord,Line : String):Boolean;
  46. (*---------------------------------------------------------------------------*
  47.   Find a word in a ; delimited list
  48.  *---------------------------------------------------------------------------*)
  49. Function CheckNameList(FWord,Line : String):Boolean;
  50.  
  51. (*---------------------------------------------------------------------------*
  52.   Find an Item by name in a object list
  53.  *---------------------------------------------------------------------------*)
  54. Function FindItem(StartRec : Integer;Item : String):Integer;
  55. Function FussyFindItem(StartRec : Integer;Item : String):Integer;
  56.  
  57. (*---------------------------------------------------------------------------*
  58.   Check if an object is in the current location
  59.  *---------------------------------------------------------------------------*)
  60. Function ObjectIsHere(Current : ContextType;Item : String):Integer;
  61.  
  62. (*---------------------------------------------------------------------------*
  63.   Show a list of items in a contents list
  64.  *---------------------------------------------------------------------------*)
  65. Procedure List_Things(StartRec : Integer;ShowAll : Boolean);
  66.  
  67. (*---------------------------------------------------------------------------*
  68.   Show all the players in a contents list
  69.  *---------------------------------------------------------------------------*)
  70. Procedure List_Players(Current : ContextType;StartRec : Integer);
  71.  
  72. (*---------------------------------------------------------------------------*
  73.   Find an object by name. Return the object nr.
  74.  *---------------------------------------------------------------------------*)
  75. Function Str2ObjNr(Var Current : ContextType;InpStr : String):Integer;
  76. Function FussyStr2ObjNr(Var Current : ContextType;InpStr : String):Integer;
  77.  
  78. (*---------------------------------------------------------------------------*
  79.   Show a file on screen. Paginated
  80.  *---------------------------------------------------------------------------*)
  81. Procedure ShowFile(FileName : ComStr);
  82.  
  83. (*---------------------------------------------------------------------------*
  84.   Translate the objectnames in an expression to ObjectNumbers
  85.  *---------------------------------------------------------------------------*)
  86. Procedure TranslateExpression(Current : ContextType;Var Expr : String);
  87.  
  88. (*---------------------------------------------------------------------------*
  89.  Check if a user finds a pennie
  90.  *---------------------------------------------------------------------------*)
  91. Procedure Generate_Pennies(Current : ContextType);
  92.  
  93.  
  94. (*---------------------------------------------------------------------------*
  95.    Login. Checks name, creates new users.
  96.  *---------------------------------------------------------------------------*)
  97. Type LogInTypes = ( NoLogin,NormalLogin,NewLogin,AskedQUIT,
  98.                     ShowWho,ShowVersion);
  99. Function LogIn(Var Current : ContextType):LogInTypes;
  100.  
  101. (*---------------------------------------------------------------------------*
  102.   Create a new object.
  103.  *---------------------------------------------------------------------------*)
  104. Function CreateNewObject(Var Current : ContextType;
  105.                              ObjType : Byte;
  106.                              Name    : String;
  107.                              Cost    : Integer):Integer;
  108.  
  109. Implementation
  110.  
  111. (*---------------------------------------------------------------------------*)
  112. Function Str2ObjNr(Var Current : ContextType;InpStr : String):Integer;
  113. Var Err   : Integer;
  114.     ObjNr : Integer;
  115. Begin
  116. InpStr:=UpStr(InpStr);
  117. If InpStr=Current.PlayerName
  118.    Then Begin
  119.         Str2ObjNr:=Current.Player;
  120.         Exit;
  121.         End;
  122.  
  123. If InpStr='ME'
  124.    Then Begin
  125.         Str2ObjNr:=Current.Player;
  126.         Exit;
  127.         End;
  128.  
  129. If InpStr='HERE'
  130.    Then Begin
  131.         Str2ObjNr:=Current.Room;
  132.         Exit;
  133.         End;
  134.  
  135. If InpStr[1]='#'
  136.    Then Begin
  137.         Delete(InpStr,1,1);
  138.         Val(InpStr,Objnr,Err);
  139.         If (Err<>0) Or (Not Current.DB.ExistObj(ObjNr))
  140.            Then Begin
  141.                 My_WriteLn('Illegal objectnumber.');
  142.                 ObjNr:=NOTHING;
  143.                 End;
  144.         End
  145.    Else Begin
  146.         Current.DB.ReadObj(Current.Player);
  147.         ObjNr:=FindItem(Current.DB.ObjRec.Contents,InpStr);
  148.  
  149.         If ObjNr=NOTHING
  150.            Then Begin
  151.                 Current.DB.ReadObj(Current.Room);
  152.                 ObjNr:=FindItem(Current.DB.ObjRec.Contents,InpStr);
  153.                 End;
  154.  
  155.         If ObjNr=NOTHING
  156.            Then ObjNr:=FindItem(Current.DB.ObjRec.Exits,InpStr);
  157.  
  158.         If (ObjNR=NOTHING) And
  159.            CheckNameList(InpStr,Current.DB.ObjRec.Name)
  160.            Then ObjNr:=Current.Room;
  161.  
  162.         End;
  163. Str2ObjNr:=ObjNr;
  164. End;
  165.  
  166. Function FussyStr2ObjNr(Var Current : ContextType;InpStr : String):Integer;
  167. Var Err   : Integer;
  168.     ObjNr : Integer;
  169. Begin
  170. InpStr:=UpStr(InpStr);
  171. Current.DB.ReadObj(Current.Player);
  172. ObjNr:=FussyFindItem(Current.DB.ObjRec.Contents,InpStr);
  173.  
  174. If ObjNr=NOTHING
  175.   Then Begin
  176.        Current.DB.ReadObj(Current.Room);
  177.        ObjNr:=FussyFindItem(Current.DB.ObjRec.Contents,InpStr);
  178.        End;
  179.  
  180. If ObjNr=NOTHING
  181.   Then ObjNr:=FussyFindItem(Current.DB.ObjRec.Exits,InpStr);
  182. FussyStr2ObjNr:=ObjNr;
  183. End;
  184.  
  185.  
  186. (*---------------------------------------------------------------------------*)
  187. Procedure MoveTo(ObjNr,ToObj : Integer);
  188. Var Dum    : Database;
  189.     ORec   : ObjRecord;
  190.     From   : Integer;
  191.     CurrNr : Integer;
  192. Begin
  193. Lock('Move To '+Dum.Name);
  194.  
  195. Dum.Init;
  196. Dum.ReadObj(ObjNr);
  197. ORec:=Dum.ObjRec;
  198. From:=Dum.ObjRec.Location;
  199. Dum.ReadObj(From);
  200.  
  201.  
  202. { Unlink record }
  203. If Dum.ObjRec.Contents=ObjNr                { If obj is first in chain }
  204.    Then Begin
  205.         Dum.ObjRec.Contents:=ORec.Next;     { Unlink object            }
  206.         Dum.UpdateObj(From);                { Save source location     }
  207.         End
  208.    Else Begin
  209.         CurrNr:=Dum.ObjRec.Contents;
  210.         Dum.ReadObj(CurrNr);                { Read first item in chain }
  211.         While (Dum.ObjRec.Next<>NOTHING) And
  212.               (Dum.ObjRec.Next<>ObjNr) Do     { Search for the object    }
  213.           Begin
  214.           CurrNr:=Dum.ObjRec.Next;
  215.           Dum.ReadObj(Dum.ObjRec.Next);
  216.           End;
  217. {**}    Dum.ObjRec.Next:=ORec.Next;         { Unlink the object        }
  218.         Dum.UpdateObj(CurrNr);              { Update source record     }
  219.         End;
  220.  
  221. { Link in }
  222.  
  223. Dum.ReadObj(ToObj);
  224. CurrNr:=ToObj;
  225. If Dum.ObjRec.Contents=NOTHING
  226.    Then Dum.ObjRec.Contents:=ObjNr
  227.    Else Begin
  228.         CurrNr:=Dum.ObjRec.Contents;
  229.         Dum.ReadObj(CurrNr);
  230.         While Dum.ObjRec.Next<>NOTHING Do
  231.           Begin
  232.           CurrNr:=Dum.ObjRec.Next;
  233.           Dum.ReadObj(CurrNr);
  234.           End;
  235.         Dum.ObjRec.Next:=ObjNr;
  236.         End;
  237. Dum.UpdateObj(CurrNr);
  238.  
  239. ORec.Location:=ToObj;
  240. ORec.Next:=NOTHING;
  241. Dum.ObjRec:=ORec;               { Prepare object for saving              }
  242. Dum.UpdateObj(ObjNr);           { Save object                            }
  243. Dum.Final;
  244.  
  245. Unlock;
  246. End;
  247.  
  248. (*--------------------------------------------------------------------------*)
  249. Procedure HandleDrones( ExitNr   : Integer;
  250.                         Current  : ContextType;
  251.                         FromRoom : Integer);
  252. Var Dum    : Database;
  253.     GetRec : Integer;
  254. Begin
  255. Dum.Init;
  256. Dum.ReadObj(FromRoom);
  257. If Dum.ObjRec.Contents=NOTHING
  258.    Then Begin
  259.         Dum.Final;
  260.         Exit;
  261.         End;
  262.  
  263. GetRec:=Dum.ObjRec.Contents;
  264.  
  265. While GetRec<>NOTHING Do
  266.  Begin
  267.  Dum.ReadObj(GetRec);
  268.  
  269.  If (Dum.ObjRec.ObjType = Drone_Type) And
  270.     Dum.IsOwnedBy(Current.Player)
  271.     Then Begin
  272.          GeneralRemarkToAllHere(Dum.Name+' follows '+Current.Playername);
  273.          MoveTo(Dum.CObjNr,Current.Room);
  274.          End;
  275.  GetRec:=Dum.ObjRec.Next;
  276.  End;
  277. Dum.Final;
  278. End;
  279.  
  280.  
  281. (*---------------------------------------------------------------------------*)
  282. Procedure Unlink(ObjNr : Integer);
  283. Var Dum    : Database;
  284.     ORec   : ObjRecord;
  285.     From   : Integer;
  286.     CurrNr : Integer;
  287. Begin
  288. Lock('Unlink ');
  289.  
  290. Dum.Init;
  291. Dum.ReadObj(ObjNr);
  292. ORec:=Dum.ObjRec;
  293.  
  294. From:=Dum.ObjRec.Location;
  295. Dum.ReadObj(From);
  296.  
  297. { Unlink record }
  298. If Dum.ObjRec.Contents=ObjNr                { If obj is first in chain }
  299.    Then Begin
  300.         Dum.ObjRec.Contents:=ORec.Next;     { Unlink object            }
  301.         Dum.UpdateObj(From);                { Save source location     }
  302.         End
  303.    Else Begin
  304.         CurrNr:=Dum.ObjRec.Contents;
  305.         Dum.ReadObj(Dum.ObjRec.Contents);   { Read first item in chain }
  306.         While Dum.ObjRec.Next<>ObjNr Do     { Search for the object    }
  307.           Begin
  308.           CurrNr:=Dum.ObjRec.Next;
  309.           Dum.ReadObj(Dum.ObjRec.Next);
  310.           End;
  311.         Dum.ObjRec.Next:=ORec.Next;         { Unlink the object        }
  312.         Dum.UpdateObj(CurrNr);              { Update source record     }
  313.         End;
  314. Dum.Final;
  315. Unlock;
  316. End;
  317.  
  318.  
  319. (*---------------------------------------------------------------------------*)
  320. Function CheckName(S,List : String):Boolean;
  321. Var Tok : String;
  322.     C   : Byte;
  323. Begin
  324. For C:=1 To Length(S) do
  325.  S[C]:=Upcase(S[C]);
  326. For C:=1 To Length(List) Do
  327.  List[C]:=UpCase(List[C]);
  328.  
  329. Repeat
  330.  C:=1;
  331.  Tok:='';
  332.  
  333.  While (C<=Length(List)) And (List[C]<>';') Do
  334.   Begin
  335.   Tok:=Tok+List[C];
  336.   Inc(C);
  337.   End;
  338.  Delete(List,1,C);
  339.  Tok:=CleanUp(Tok);
  340. Until (Tok='') Or (Tok=S);
  341. CheckName:=Tok=S;
  342. End;
  343.  
  344. (*---------------------------------------------------------------------------*)
  345. Procedure List_Things(StartRec : Integer;ShowAll : Boolean);
  346. Var Tmp    : Database;
  347.     GetRec : Integer;
  348.     Found  : Boolean;
  349.     Count  : Word;
  350. Begin
  351. Tmp.Init;
  352. Found:=False;
  353. GetRec:=StartRec;
  354. Count:=0;
  355. My_Write('You see ');
  356. While (Not Found) and (Tmp.ObjRec.Next<>NOTHING) Do
  357.  Begin
  358.  Tmp.ReadObj(GetRec);
  359.  If (ShowAll or Tmp.IsThing) And
  360.     (Not Tmp.IsInvisible)
  361.     Then Begin
  362.          If Count=0
  363.             Then My_WriteLn('');
  364.          If Tmp.IsForSale
  365.             Then My_WriteLn(' '+Tmp.Name+' ('+Nr2Str(Tmp.ObjRec.Pennies)+'p).')
  366.             Else My_WriteLn(' '+Tmp.Name);
  367.          Inc(Count);
  368.          End;
  369.  GetRec:=Tmp.ObjRec.Next;
  370.  End;
  371. If Count=0
  372.    Then My_WriteLn('nothing special.');
  373. Tmp.Final;
  374. End;
  375.  
  376. (*---------------------------------------------------------------------------*)
  377. Procedure List_Players(Current : ContextType;StartRec : Integer);
  378. Var Tmp    : Database;
  379.     GetRec : Integer;
  380.     Found  : Boolean;
  381.     Count  : Word;
  382. Begin
  383. Tmp.Init;
  384. Found:=False;
  385. GetRec:=StartRec;
  386. Count:=0;
  387. While (Not Found) and (GetRec<>NOTHING) Do
  388.  Begin
  389.  Tmp.ReadObj(GetRec);
  390.  If (Tmp.IsPlayer Or Tmp.IsDrone) and
  391.     (Not Tmp.IsInvisible) And
  392.     (Tmp.CObjNr<>Current.Player)
  393.     Then Begin
  394.          If Tmp.IsDrone
  395.             Then Begin
  396.                  If Tmp.IsOwnedBy(Current.Player)
  397.                     Then My_WriteLn(Tmp.name+' is here.')
  398.                     Else My_WriteLn('You see '+Tmp.Name);
  399.                  End
  400.             Else Begin
  401.                  If IsAlive(Tmp.CObjNr) Or IsAlive(Tmp.ObjRec.Owner)
  402.                     Then My_WriteLn(Tmp.Name+' is here.');
  403.                  End;
  404.          Inc(Count);
  405.          End;
  406.  GetRec:=Tmp.ObjRec.Next;
  407.  End;
  408. Tmp.Final;
  409. End;
  410.  
  411. (*---------------------------------------------------------------------------*)
  412. Function FindItem(StartRec : Integer;Item : String):Integer;
  413. Var Tmp    : Database;
  414.     GetRec : Integer;
  415.     Found  : Boolean;
  416. Begin
  417. Tmp.Init;
  418. Found:=False;
  419. GetRec:=StartRec;
  420. While (Not Found) and (GetRec<>NOTHING) Do
  421.  Begin
  422.  Tmp.ReadObj(GetRec);
  423.  If ExactWordMatch(Item,Tmp.ObjRec.Name) Or
  424.     CheckNameList(Item,Tmp.ObjRec.Name)
  425.     Then Found:=True
  426.     Else GetRec:=Tmp.ObjRec.Next;
  427.  End;
  428. Tmp.Final;
  429. If Found
  430.    Then FindItem:=GetRec
  431.    Else FindItem:=NOTHING;
  432. End;
  433.  
  434. Function FussyFindItem(StartRec : Integer;Item : String):Integer;
  435. Var Tmp    : Database;
  436.     GetRec : Integer;
  437.     Found  : Boolean;
  438. Begin
  439. Tmp.Init;
  440. Found:=False;
  441. GetRec:=StartRec;
  442. While (Not Found) and (GetRec<>NOTHING) Do
  443.  Begin
  444.  Tmp.ReadObj(GetRec);
  445.  If FussyWordMatch(Item,Tmp.ObjRec.Name) Or
  446.     CheckNameList(Item,Tmp.ObjRec.Name)
  447.     Then Found:=True
  448.     Else GetRec:=Tmp.ObjRec.Next;
  449.  End;
  450. Tmp.Final;
  451. If Found
  452.    Then FussyFindItem:=GetRec
  453.    Else FussyFindItem:=NOTHING;
  454. End;
  455.  
  456. (*---------------------------------------------------------------------------*)
  457. Function ObjectIsHere(Current : ContextType;Item : String):Integer;
  458. Var Nr : Integer;
  459. Begin
  460. Nr:=NOTHING;
  461. Current.DB.ReadObj(Current.Room);
  462. Nr:=FindItem(Current.DB.ObjRec.Contents,Item);
  463. If Nr=NOTHING
  464.    Then Nr:=FindItem(Current.DB.ObjRec.Exits,Item);
  465. If Nr=NOTHING
  466.    Then Nr:=FussyFindItem(Current.DB.ObjRec.Contents,Item);
  467.  
  468. If Nr=NOTHING
  469.    Then Begin
  470.         Current.DB.ReadObj(Current.Player);
  471.         Nr:=FindItem(Current.DB.ObjRec.Contents,Item);
  472.         End;
  473. If Nr=NOTHING
  474.    Then Nr:=FussyFindItem(Current.DB.ObjRec.Contents,Item);
  475. ObjectIsHere:=Nr;
  476. End;
  477.  
  478. (*---------------------------------------------------------------------------*)
  479. Procedure ShowFile(FileName : ComStr);
  480. Var Inp       : Text;
  481.     Line      : String;
  482.     LineCount : Byte;
  483.     Dum       : Char;
  484. Begin
  485. Assign(Inp,FileName);
  486. Reset(Inp);
  487. If IoResult<>0
  488.    Then Exit;
  489. LineCount:=0;
  490. While Not Eof(Inp) Do
  491.  Begin
  492.  ReadLn(Inp,Line);
  493.  My_WriteLn(Line);
  494.  Inc(LineCount);
  495.  If LineCount=22
  496.     Then Begin
  497.          My_Write('--- Press KEY to continue.. ---');
  498.          Dum:=My_ReadKey;
  499.          My_Write(#13);My_ClrEol;
  500.          LineCount:=0;
  501.          End;
  502.  End;
  503. Close(Inp);
  504. End;
  505.  
  506. (*---------------------------------------------------------------------------*)
  507.  
  508. Function ExactWordMatch(FWord,Line : String):Boolean;
  509. Var P       : Byte;
  510.     Temp    : String;
  511. Begin
  512. ExactWordMatch:=False;
  513. FWord:=UpStr(FWorD);
  514. Line:=UpStr(Line);
  515. Temp:='';
  516.  
  517. Repeat
  518.   P:=Pos(';',Line);
  519.   If P=0 Then P:=Length(Line)+1;
  520.   If (Line<>'') And (P>0)
  521.      Then Begin
  522.           Temp:=Copy(Line,1,P-1);
  523.           Delete(Line,1,P);
  524.           If Temp=FWord
  525.              Then Begin
  526.                   ExactWordMatch:=True;
  527.                   Exit;
  528.                   End;
  529.           End;
  530. Until (P=0) Or (Line='');
  531. End;
  532.  
  533.  
  534. Function FussyWordMatch(FWord,Line : String):Boolean;
  535. Var P       : Byte;
  536.     CC1,CC2 : Char;
  537. Begin
  538. FussyWordMatch:=False;
  539. FWord:=UpStr(FWorD);
  540. Line:=UpStr(Line);
  541. P:=Pos(FWord,Line);
  542. If P=0
  543.    Then Exit;
  544. If P=1
  545.    Then CC1:=' '
  546.    Else CC1:=Line[P-1];
  547. If (P+Length(FWord)-1)=Length(Line)
  548.    Then CC2:=' '
  549.    Else CC2:=Line[P+Length(FWord)];
  550.  
  551. FussyWordMatch:=(Not (Upcase(CC1) in ['A'..'Z','0'..'9'])) And
  552.                 (Not (Upcase(CC2) in ['A'..'Z','0'..'9']));
  553. End;
  554.  
  555. (*---------------------------------------------------------------------------*)
  556. Function RegMatch(Expr,Match : String):Boolean;
  557. Var StarPos : Byte;
  558. Begin
  559. RegMatch:=False;
  560. StarPos:=Pos('*',Expr);
  561. MemMatch:='';
  562. If StarPos>0
  563.    Then Begin
  564.         Expr:=Copy(Expr,1,StarPos-1);
  565.         If Pos(Expr,Match)=1
  566.            Then Begin
  567.                 RegMatch:=True;
  568.                 MemMatch:=LastSentence;
  569.                 Delete(MemMatch,1,Length(Expr));
  570.                 Exit;
  571.                 End;
  572.         End
  573.    Else RegMatch:=Expr=Match;
  574. End;
  575.  
  576.  
  577. Function CheckNameList(FWord,Line : String):Boolean;
  578. Var Check : String;
  579.     Stop  : Boolean;
  580. Begin
  581. FWord:=CleanUp(FWord);
  582. Line:=UpStr(Line);
  583. Check:='';
  584. Stop:=False;
  585. While (Line<>'') and (Not Stop) Do
  586.  Begin
  587.  If Pos(';',Line)>0
  588.     Then Check:=Copy(Line,1,Pos(';',Line)-1)
  589.     Else Begin
  590.          Check:=Line;
  591.          Line:='';
  592.          End;
  593.  Delete(Line,1,Length(Check)+1);
  594.  Check:=CleanUp(Check);
  595.  Stop:=RegMatch(Check,FWord);
  596.  End;
  597. CheckNameList:=Stop;
  598. End;
  599.  
  600.  
  601. (*---------------------------------------------------------------------------*)
  602. Function GetPassword:String;
  603. Var Tmp     : String;
  604.     Key     : Char;
  605.     GotChar : Boolean;
  606. Begin
  607. Tmp:='';
  608. Repeat
  609.   GotChar:=False;
  610.   Repeat
  611.    If My_KeyPressed
  612.       Then Begin
  613.            Key:=Upcase(My_ReadKey);
  614.            If Key=#00
  615.               Then Key:=My_ReadKey
  616.               Else GotChar:=True;
  617.            End;
  618.   Until GotChar;
  619.   Case Key of
  620.    #8 : Begin
  621.         If Tmp<>''
  622.            Then Begin
  623.                 Dec(Tmp[0]);
  624.                 My_Write(#8' '#8);
  625.                 End;
  626.         End;
  627.    #13: Begin
  628.         GetPassword:=Tmp;
  629.         Exit;
  630.         End;
  631.    Else Begin
  632.         If Key>=' '
  633.            Then Begin
  634.                 Tmp:=Tmp+Key;
  635.                 My_Write('#');
  636.                 End
  637.            Else My_Write(#7);
  638.         End;
  639.   End; {Case}
  640. Until False;
  641. End;
  642.  
  643.  
  644. (*---------------------------------------------------------------------------*)
  645. Function CreateNewObject(Var Current : ContextType;
  646.                              ObjType : Byte;
  647.                              Name    : String;
  648.                              Cost    : Integer):Integer;
  649. Var Temp  : ObjRecord;
  650.     RecNr : Integer;
  651.     Dum   : Database;
  652. Begin
  653. CreateNewObject:=NOTHING;
  654. Lock('New object');
  655. FillChar(Temp,SizeOf(Temp),#00);
  656.  
  657. Temp.Name:=Name;
  658. Temp.Owner:=Current.Player;
  659. If Not (ObjType in [Room_Type,Exit_Type])
  660.    Then Temp.Location:=Current.Player
  661.    Else Temp.Location:=NOTHING;
  662.  
  663. Temp.Pennies:=(Cost Div 2)-1;
  664. Temp.GenFlags:=0;
  665.  
  666. Temp.ObjType:=ObjType;
  667. Temp.Exits:=NOTHING;
  668. Temp.Contents:=NOTHING;
  669. Temp.Next:=NOTHING;
  670. Temp.Attr_Flags:=Chown_Ok_Flag;
  671.  
  672. Current.DB.ReadObj(Current.Player);
  673. If ObjType<>Room_Type
  674.    Then Begin
  675.         If (Current.DB.IsOwner(Current.Room)) Or
  676.            (Current.Level>=Wizard_Level)
  677.            Then Temp.Exits:=Current.Room
  678.            Else Temp.Exits:=Current.DB.ObjRec.Exits;
  679.         End;
  680.  
  681.  
  682. Current.DB.ObjRec:=Temp;
  683. RecNr:=Current.DB.AddObj;
  684. Current.DB.ReadObj(RecNr);
  685.  
  686. Dum.Init;
  687. Dum.ReadObj(Current.Player);
  688. If Not Dum.LevelOk(Wizard_Level)
  689.    Then Dec(Dum.ObjRec.Pennies,Cost);
  690. If (ObjType=Thing_type) Or (ObjType=Drone_Type)
  691.    Then Begin
  692.         Current.DB.ObjRec.Next:=Dum.ObjRec.Contents;
  693.         Dum.ObjRec.Contents:=RecNr;
  694.         End;
  695. Dum.UpdateObj(Current.Player);
  696. Current.DB.UpdateObj(RecNr);
  697.  
  698. Dum.Final;
  699. Current.DB.Final;
  700. Current.DB.Init;
  701.  
  702. Unlock;
  703. CreateNewObject:=RecNr;
  704. End;
  705.  
  706.  
  707. (*---------------------------------------------------------------------------*)
  708.  
  709. Const SpecialTypes : Array[1..5] of String [10]
  710.                    = ('GAME','WHO','HELP','QUIT','INFO');
  711.  
  712. Function FindSpec(S : String):Byte;
  713. Var Tmp : Byte;
  714. Begin
  715. S:=UpStr(S);
  716. Tmp:=5;
  717. While (Tmp>0) And (S<>SpecialTypes[Tmp]) Do
  718.  Dec(Tmp);
  719. FindSpec:=Tmp;
  720. End;
  721.  
  722.  
  723. Function LogIn(Var Current : ContextType):LogInTypes;
  724. Var PassWord : PassString;
  725.     PassCount: Byte;
  726.     Ok       : Boolean;
  727.     Comm     : Byte;
  728.     RecNr    : Integer;
  729.     Name     : String;
  730.     Sex      : String[1];
  731.     Answer   : Char;
  732.     Tmp      : ObjRecord;
  733.     Dum      : DataBase;
  734. Begin
  735. LogIn:=NoLogin;
  736.  
  737. Repeat
  738.  Repeat
  739.    My_ClrScr;
  740.  
  741.    ShowFile(HomeDir+'LOGO.MUD');
  742.    My_WriteLn(HighLight+'MyMUD '+MudVersion+'/P '+CompileDate+LowLight);
  743.    My_WriteLn('Type HELP for available options.');
  744.    My_WriteLn('');
  745.  
  746.    Answer:=' ';
  747.    My_Write('?> ');
  748.    My_ReadLn(Name);
  749.    Name:=CleanUp(Name);
  750.    If Name[1]='?'
  751.       Then Name:='HELP';
  752.    Comm:=FindSpec(Name);
  753.    Case Comm Of
  754.      1 : Begin
  755.          if ExistFile(WorldPath+'WORLD.INF')
  756.             Then Begin
  757.                  My_ClrScr;
  758.                  ShowFile(WorldPath+'WORLD.INF');
  759.                  End
  760.             Else My_WriteLn('No info on this game available.');
  761.          My_WriteLn('');
  762.          My_WaitForKey('─── Press a key ───');
  763.          Name:='';
  764.          End;
  765.      2 : Begin
  766.          LogIn:=ShowWho;
  767.          Exit;
  768.          End;
  769.      3 : Begin
  770.          My_ClrScr;
  771.          My_WriteLn('');
  772.          My_WriteLn('  GAME - Info on this game');
  773.          My_WriteLn('  HELP - this help');
  774.          My_WriteLn('  INFO - Information about MyMUD');
  775.          My_WriteLn('  QUIT - Abort the game.');
  776.          My_WriteLn('  WHO  - Who''s logged in at this moment');
  777.          My_WriteLn('  or your playername to log in.');
  778.          My_WriteLn('');
  779.          My_WaitForKey('─── Press a key ───');
  780.          My_ClrScr;
  781.          Name:='';
  782.          End;
  783.      4 : Begin
  784.          LogIn:=AskedQuit;
  785.          Exit;
  786.          End;
  787.      5 : Begin
  788.          LogIn:=ShowVersion;
  789.          Exit;
  790.          End;
  791.      Else Begin
  792.           Current.Player:=Current.DB.FindPlayer(UpStr(Name));
  793.           If (Current.Player=NOTHING)
  794.              Then Begin
  795.                   If My_YesNo('Did you write your name correct?','Y')='N'
  796.                      Then Begin
  797.                           Name:='';
  798.                           End;
  799.                   My_WriteLn('');
  800.                   End;
  801.           End;
  802.    End; {Case}
  803.  Until Name<>'';
  804.  
  805.  LogIn:=NormalLogin;
  806.  If (Current.Player<>NOTHING) And
  807.     IsAlive(Current.Player)
  808.     Then Begin
  809.          My_WriteLn('You''re already logged on. Please log out first!');
  810.          Login:=ASKEDQuit;
  811.          Exit;
  812.          End;
  813.  
  814.  If Current.Player<>NOTHING
  815.     Then Begin
  816.          PassCount:=0;
  817.          Repeat
  818.           If UpStr(Name)<>'GUEST'
  819.              Then Begin
  820.                   My_Write('Password: ');
  821.                   Password:=GetPassword;
  822.                   If UpStr(Current.DB.ObjRec.Password)<>UpStr(Password)
  823.                      Then Begin
  824.                           My_WriteLn(' -- Illegal password.');
  825.                           Inc(PassCount);
  826.                           If PassCount>3
  827.                              Then Halt(5);
  828.                           End
  829.                      Else PassCount:=0;
  830.                   End;
  831.          Until (PassCount=0);
  832.          Current.PlayerName:=Current.DB.Name;
  833.          Current.Room:=Current.DB.ObjRec.Location;
  834.          Current.Note:='';
  835. {*}      Current.DB.ObjRec.ObjType:=Player_Type;
  836. {*}      Current.DB.UpdateObj(Current.Player);
  837.          Exit;
  838.          End;
  839.  
  840.  LogIn:=NewLogin;
  841.  FillChar(Tmp,SizeOf(Tmp),#00);
  842.  With Tmp Do
  843.   Begin
  844.   Contents  := NOTHING;
  845.   Location  := 0;
  846.   Next      := NOTHING;
  847.   Pennies   := 5;
  848.   ObjType   := Player_Type;
  849.   Exits     :=0;
  850.   Owner     :=NOTHING;
  851.   Garbage   :=NOTHING;
  852.  
  853.   If UpStr(name)='GUEST'
  854.      Then ObjLevel := Guest_Level
  855.      Else ObjLevel := Player_Level;
  856.   End; {With}
  857.  
  858.  Tmp.Name:=Name;
  859.  My_WriteLn('Welcome new user!');
  860.  My_WriteLn('');
  861.  
  862.  Repeat
  863.   My_Write('Are you Male/Femal/Neuter/Quit? [M/F/N/Q]: ');
  864.   My_ReadLn(Sex);
  865.  Until Upcase(Sex[1]) in ['M','F','N','Q'];
  866.  
  867.  Case Upcase(Sex[1]) Of
  868.   'N' : Tmp.Sex:=Ord(Neuter_Gender);
  869.   'F' : Tmp.Sex:=Ord(Female_Gender);
  870.   'M' : Tmp.Sex:=Ord(Male_Gender);
  871.   'Q' : Begin
  872.         LogIn:=AskedQUIT;
  873.         Exit;
  874.         End;
  875.  End;
  876.  
  877.  Repeat
  878.    My_Write('Give a password: ');
  879.    Tmp.Password:=GetPassword;
  880.    Tmp.Password:=CleanUp(Tmp.Password);
  881.    My_WriteLn('');
  882.    My_Write('Again: ');
  883.    Ok:=(Tmp.Password<>'') And (Tmp.Password=CleanUp(GetPassword));
  884.    My_WriteLn('');
  885.  Until Ok;
  886.  
  887.  Lock('Adding new user');
  888.  
  889.  Current.DB.ObjRec:=Tmp;
  890.  RecNr:=Current.DB.AddObj;
  891.  Current.DB.ReadObj(RecNr);
  892.  Current.DB.ObjRec.Owner:=RecNr;
  893.  Dum.Init;
  894.  Dum.ReadObj(0);
  895.  Current.DB.ObjRec.Next:=Dum.ObjRec.Contents;
  896.  Current.DB.ObjRec.Location:=0;
  897.  Dum.ObjRec.Contents:=RecNr;
  898.  Dum.UpdateObj(0);
  899.  Current.DB.UpdateObj(RecNr);
  900.  
  901.  Current.PlayerName:=Tmp.Name;
  902.  Current.Player:=RecNr;
  903.  Current.Room:=0;
  904.  
  905.  Current.DB.AddPlayer(Current.Player);
  906.  Dum.Final;
  907.  
  908.  Current.DB.Final;
  909.  Current.DB.Init;
  910.  
  911.  UpdateNodeInfo(Current);
  912.  Unlock;
  913.  Exit;
  914. Until False;
  915. LogIn:=NewLogin;
  916. End;
  917.  
  918.  
  919. (*---------------------------------------------------------------------------*)
  920. Procedure TranslateExpression(Current : ContextType;Var Expr : String);
  921. Var NewLine : String;
  922.     Temp    : String[40];
  923.     ObjNr   : Integer;
  924.     C       : Byte;
  925. Begin
  926. Expr:=Expr+' ';
  927. NewLine:='';
  928. Temp:='';
  929. C:=1;
  930. While C<=Length(Expr) Do
  931.  Begin
  932.  If (Expr[C] in ['A'..'Z','@']) And
  933.     (C<=Length(Expr))
  934.     Then Temp:=Temp+Expr[C]
  935.     Else Begin
  936.          If Temp<>''
  937.             Then Begin
  938.                  If Temp[1]='@'
  939.                     Then Begin
  940.                          NewLine:=NewLine+Temp;
  941.                          Dec(C);
  942.                          End
  943.                     Else Begin
  944.                          If Temp = 'ME'
  945.                             Then ObjNr:=Current.Player
  946.                             Else ObjNr:=Str2ObjNr(Current,Temp);
  947.                          NewLine:=NewLine+Nr2Str(ObjNr)+Expr[C];
  948.                          End;
  949.                  temp:='';
  950.                  End
  951.             Else NewLine:=NewLine+Expr[C];
  952.          End;
  953.  Inc(C);
  954.  End; {While}
  955. Expr:=NewLine;
  956. End;
  957.  
  958. (*--------------------------------------------------------------------------*)
  959. Procedure Generate_Pennies(Current : ContextType);
  960. Var OldRec : ObjRecord;
  961.  
  962. Begin
  963. Lock('Found penny');
  964. Current.DB.ReadObj(Current.Room);
  965. OldRec:=Current.DB.ObjRec;
  966. Current.DB.ReadObj(Current.Player);
  967. If (Not (Current.DB.LevelOk(Wizard_Level) Or (OldRec.Owner=Current.Player))) And
  968.    (Current.DB.ObjRec.Pennies<=MAX_PENNIES) And
  969.    (Random(PENNY_RATE)=0)
  970.    Then Begin
  971.         My_WriteLn('You found a penny!');
  972.         Inc(Current.DB.ObjRec.Pennies);
  973.         Current.DB.UpdateObj(Current.Player);
  974.  
  975.         End;
  976. Unlock;
  977. End;
  978.  
  979. End.
  980.